package com.itheima.web.service.impl.sms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.service.sms.RecommendSubjectService;
import com.itheima.vo.sms.RecommendSubject;
import com.itheima.web.mapper.sms.RecommendSubjectMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.util.List;

@DubboService
public class RecommendSubjectServiceImpl extends ServiceImpl<RecommendSubjectMapper, RecommendSubject> implements RecommendSubjectService {
    @Override
    public Page<RecommendSubject> getPage(Integer pageNum, Integer pageSize, String subjectName, Integer recommendStatus) {
        Page<RecommendSubject> page=new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<RecommendSubject> rslqw =new LambdaQueryWrapper<>();
        rslqw.like(Strings.isNotEmpty(subjectName),RecommendSubject::getSubjectName, subjectName);
        rslqw.eq(recommendStatus!=null,RecommendSubject::getRecommendStatus,recommendStatus);
        this.page(page, rslqw);
        return page;
    }

    @Override
    public void updateStatus(List<Integer> ids, Integer recommendStatus) {
        List<RecommendSubject> recommendSubjects = this.listByIds(ids);
        for (RecommendSubject recommendSubject : recommendSubjects) {
            recommendSubject.setRecommendStatus(recommendStatus);
        }

        this.updateBatchById(recommendSubjects);
    }
}
